--来自冥界の低语
local s,id=GetID()
function s.initial_effect(c)
	--
	local e0=Effect.CreateEffect(c)
	e0:SetDescription(aux.Stringid(id,0))
	e0:SetCategory(CATEGORY_TOHAND)
	e0:SetProperty(EFFECT_FLAG_UNCOPYABLE)
	e0:SetType(EFFECT_TYPE_IGNITION)
	e0:SetRange(LOCATION_DECK)
	e0:SetCondition(s.condition)
	e0:SetTarget(s.thtg)
	e0:SetOperation(s.thop)
	c:RegisterEffect(e0) 
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCondition(s.condition)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
	--
	local e2=Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id,1))
	e2:SetCategory(CATEGORY_TOHAND)
	e2:SetType(EFFECT_TYPE_IGNITION)
	e2:SetRange(LOCATION_GRAVE)
	e2:SetCondition(s.thcon)
	e2:SetTarget(s.thtg)
	e2:SetOperation(s.thop)
	c:RegisterEffect(e2)
end
s.listed_names={33533619}
local typeMap = {
	[0] = TYPE_MONSTER,
	[1] = TYPE_SPELL,
	[2] = TYPE_TRAP,
	[3] = TYPE_NORMAL,
	[4] = TYPE_EFFECT,
	[5] = TYPE_FUSION,
	[6] = TYPE_RITUAL,
	[7] = TYPE_SPIRIT,
	[8] = TYPE_UNION,
	[9] = TYPE_GEMINI,
	[10] = TYPE_TUNER,
	[11] = TYPE_SYNCHRO,
	[12] = TYPE_TOKEN,
	[13] = TYPE_MAXIMUM,
	[14] = TYPE_QUICKPLAY,
	[15] = TYPE_CONTINUOUS,
	[16] = TYPE_EQUIP,
	[17] = TYPE_FIELD,
	[18] = TYPE_COUNTER,
	[19] = TYPE_FLIP,
	[20] = TYPE_TOON,
	[21] = TYPE_XYZ,
	[22] = TYPE_PENDULUM,
	[23] = TYPE_SPSUMMON,
	[24] = TYPE_LINK,
	[25] = TYPE_SKILL,
	[26] = TYPE_ACTION,
	[27] = TYPE_PLUS,
	[28] = TYPE_MINUS,
	[29] = TYPE_ARMOR
}
function s.condition(e)
	return Duel.IsExistingMatchingCard(aux.FaceupFilter(Card.IsCode,33533619),e:GetHandlerPlayer(),LOCATION_MZONE,0,1,nil)
end
function s.thtg(e,tp,eg,ep,ev,re,r,rp,chk)
	local c=e:GetHandler()
	if chk==0 then return c:IsAbleToHand() end
	Duel.SetOperationInfo(0,CATEGORY_TOHAND,c,1,0,0)
end
function s.thop(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	if c:IsRelateToEffect(e) then
		Duel.SendtoHand(c,nil,REASON_EFFECT)
		Duel.ConfirmCards(1-tp,c)
	end
end
function s.target(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(Card.IsFaceup,tp,LOCATION_MZONE,LOCATION_MZONE,1,nil) end
	local sg=Duel.GetMatchingGroup(aux.TRUE,tp,LOCATION_MZONE,LOCATION_MZONE,nil)
	Duel.SetOperationInfo(0,CATEGORY_DESTROY,sg,#sg,0,0)
end
function s.activate(e,tp,eg,ep,ev,re,r,rp)
	local sg=Duel.GetMatchingGroup(aux.TRUE,tp,LOCATION_MZONE,LOCATION_MZONE,nil)
	if #sg==0 then return end
	local c=e:GetHandler()
	local op=0 
	if Duel.SelectYesNo(tp,aux.Stringid(id,1)) then
		local race=Duel.AnnounceRace(tp,1,RACE_ALL)
		for tc in sg:Iter() do
			local e1=Effect.CreateEffect(c)
			e1:SetType(EFFECT_TYPE_SINGLE)
			e1:SetCode(EFFECT_CHANGE_RACE)
			e1:SetValue(race)
			e1:SetReset(RESET_EVENT|RESETS_STANDARD)
			tc:RegisterEffect(e1)
		end
		op=1
	end
	if Duel.SelectYesNo(tp,aux.Stringid(id,2)) then
		local att=Duel.AnnounceAttribute(tp,1,ATTRIBUTE_ALL)
		for tc in sg:Iter() do
			local e1=Effect.CreateEffect(c)
			e1:SetType(EFFECT_TYPE_SINGLE)
			e1:SetCode(EFFECT_CHANGE_ATTRIBUTE)
			e1:SetValue(att)
			e1:SetReset(RESET_EVENT|RESETS_STANDARD)
			tc:RegisterEffect(e1)
		end
		op=1
	end
	if op==0 or Duel.SelectYesNo(tp,aux.Stringid(id,3)) then
		local typ=0
		local typlist={1050,1051,1052,1054,1055,1056,1057,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,aux.Stringid(id,4),aux.Stringid(id,5),aux.Stringid(id,6)}
		Duel.Hint(HINT_SELECTMSG,tp,aux.Stringid(id,7))
		local opt1=Duel.SelectOption(tp,table.unpack(typlist))
		if typeMap[opt1] then
			typ=typ|typeMap[opt1]
		end
		::cancel::
		if Duel.SelectYesNo(tp,aux.Stringid(id,8)) then
			Duel.Hint(HINT_SELECTMSG,tp,aux.Stringid(id,7))
			local opt2=Duel.SelectOption(tp,table.unpack(typlist))
			if opt2==opt1 then
				Debug.ShowHint("请勿重复宣言")
				goto cancel
			end
			if typeMap[opt2] then
				typ=typ|typeMap[opt2]
			end
		end
		for tc in sg:Iter() do
			local e1=Effect.CreateEffect(c)
			e1:SetType(EFFECT_TYPE_SINGLE)
			e1:SetCode(EFFECT_CHANGE_TYPE)
			e1:SetValue(typ)
			e1:SetReset(RESET_EVENT|RESETS_STANDARD)
			tc:RegisterEffect(e1)
		end
	end
	if e:IsHasType(EFFECT_TYPE_ACTIVATE) and c:GetFlagEffect(id)~=0 then
		Duel.SendtoDeck(c,tp,-2,REASON_EFFECT)
	end
end
function s.thcon(e,tp,eg,ep,ev,re,r,rp)
	return Duel.IsExistingMatchingCard(aux.FaceupFilter(Card.IsSetCard,0x66f),tp,0x3c,0,1,nil)
end
function s.thtg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return e:GetHandler():IsAbleToHand() end
	Duel.SetOperationInfo(0,CATEGORY_TOHAND,e:GetHandler(),1,0,LOCATION_GRAVE)
end
function s.thop(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	if c:IsRelateToEffect(e) then
		Duel.SendtoHand(c,nil,REASON_EFFECT)
		Duel.ConfirmCards(1-tp,c)
		c:RegisterFlagEffect(id,0,0,1)
	end
end